package com.yxy.controller;

import com.yxy.base.BusinessException;
import com.yxy.base.RestResponse;
import com.yxy.dto.system.TenantListDto2;
import com.yxy.feign.AuthService;
import com.yxy.feign.authModel.AppDataDicDetail;
import com.yxy.model.TenantExtend;
import com.yxy.service.TenantService;
import com.yxy.utils.DataDicHelper;
import com.yxy.utils.SystemSettingHelper;
import com.yxy.utils.TokenCheckUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author yuxiaoyang
 * 字典接口测试
 */
@RestController
@Slf4j
@RequestMapping("/data-dic")
public class DataDicController {

  @Autowired
  private TokenCheckUtil tokenCheckUtil;

  @Autowired
  private AuthService authService;

  @Autowired
  private SystemSettingHelper systemSettingHelper;

  @Autowired
  private DataDicHelper dataDicHelper;

  // 根据主键id获取某个字典项的详情
  @GetMapping("/getDataDicDetailById")
  public RestResponse getDataDicDetailById() throws BusinessException {
    String invokeUnionAuthToken = tokenCheckUtil.getInvokeUnionAuthToken();
    return authService.getDataDicDetailById(10L, invokeUnionAuthToken);
  }

  // 根据字典项的value获取某个字典项的详情
  @GetMapping("/getDataDicDetailByValue")
  public RestResponse getDataDicDetailByValue(@RequestParam("value") String value) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    AppDataDicDetail appDataDicDetail = dataDicHelper.getDataDicDetailByValue(value);
    restResponse.setContent(appDataDicDetail);
    return restResponse;
  }

  // 根据paramKey获取某个系统设置参数
  @GetMapping("/getSystemSettingParam")
  public RestResponse getSystemSettingParam(@RequestParam("paramKey") String paramKey) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(systemSettingHelper.getSystemSettingParam(paramKey));
    return restResponse;
  }
}
